//
//  BigImageCell.m
//  天下事
//
//  Created by dlios on 15-7-11.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "BigImageCell.h"
#import "UIImageView+WebCache.h"

#import "NetWorkTools.h"

@implementation BigImageCell
- (void)dealloc
{
    [_BigImagetitle release];
    [_bigImg release];
    [super dealloc];
}

- (void)awakeFromNib {
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIView *headerview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 245)];
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 245);
        layout.minimumLineSpacing = 0;
        layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        self.collectview = [[UICollectionView alloc]initWithFrame:headerview.frame collectionViewLayout:layout];

        self.collectview.pagingEnabled = YES;
        self.collectview.delegate = self;
        self.collectview.dataSource = self;

        self.collectview.showsHorizontalScrollIndicator = NO;
        self.collectview.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        self.collectview.backgroundColor = [UIColor whiteColor];
        [self.collectview registerClass:[BigImageCollectionViewcell class]
             forCellWithReuseIdentifier:@"UICollectionViewCell"];
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        [self.contentView addSubview:self.collectview];
        
        self.pagecontroler = [[UIPageControl alloc]init];
        self.pagecontroler.currentPageIndicatorTintColor = [UIColor cyanColor];
        self.pagecontroler.pageIndicatorTintColor = [UIColor blackColor];
        self.pagecontroler.numberOfPages = 2;
        self.pagecontroler.currentPage = 0;
        
//             self.pagecontroler.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.pagecontroler];
    
        [self.collectview reloadData];
    }
    return self;
}


- (void)setArrayList1:(NSMutableArray *)arrayList1{
    _arrayList1 = arrayList1;
   [self.collectview reloadData];
}


- (void)pagechange{
    [self.collectview setContentOffset:CGPointMake(375 * self.pagecontroler.currentPage, 0) animated:YES];
    
}
- (void)layoutSubviews{
    [super layoutSubviews];
        CGRect rect = CGRectMake(300, 200, 100, 20);
    self.pagecontroler.frame = rect;
    
    
}

//- (void)setNm:(NewsModel *)nm{
//    _nm = nm;
//    [self.bigImg sd_setImageWithURL:[NSURL URLWithString:nm.imgsrc]];
//    self.BigImagetitle.text = nm.title;
//}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 2;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    BigImageCollectionViewcell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UICollectionViewCell" forIndexPath:indexPath];

    [cell.bigImg sd_setImageWithURL:[NSURL URLWithString:[self.arrayList1[indexPath.item] objectForKey:@"imgsrc"]]];
    cell.BigImagetitle.text = [[self.arrayList2 firstObject] title];
    self.temarr1 = [NSMutableArray array];
    self.temarr1 = self.arrayList1;
    

    return cell;
    
    
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    NSInteger x = self.collectview.contentOffset.x / self.view.frame.size.width;
    self.pagecontroler.currentPage = x;
    
}

@end
